/***********************************************************************************************************************
 *  FILE DESCRIPTION
 *  ------------------------------------------------------------------------------------------------------------------*/
/** \file
 *  \brief        Boot manager implementation
 *
 *  --------------------------------------------------------------------------------------------------------------------
 *  COPYRIGHT
 *  --------------------------------------------------------------------------------------------------------------------
 *  \par Copyright
 *  \verbatim
 *  Copyright (c) 2015 by Vector Informatik GmbH.                                                  All rights reserved.
 *
 *                This software is copyright protected and proprietary to Vector Informatik GmbH.
 *                Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
 *                All other rights remain with Vector Informatik GmbH.
 *  \endverbatim
 */
/**********************************************************************************************************************/
/***********************************************************************************************************************
 *  AUTHOR IDENTITY
 *  --------------------------------------------------------------------------------------------------------------------
 *  Name                          Initials      Company
 *  --------------------------------------------------------------------------------------------------------------------
 *  Christian Baeuerle            CB            Vector Informatik GmbH
 *  --------------------------------------------------------------------------------------------------------------------
 *  REVISION HISTORY
 *  --------------------------------------------------------------------------------------------------------------------
 *  Version    Date        Author  Change Id        Description
 *  --------------------------------------------------------------------------------------------------------------------
 *  02.00.00   2015-02-28  CB                       First implementation
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  INCLUDES
 **********************************************************************************************************************/
#include "fbl_bm.h"
#include "fbl_apbm.h"

/***********************************************************************************************************************
 *  VERSION
 **********************************************************************************************************************/

#if ( FBLMAIN_BM_VERSION != 0x0200u ) || \
    ( FBLMAIN_BM_RELEASE_VERSION != 0x00u )
# error "Error in fbl_bm.c: Source and header file are inconsistent!"
#endif
#if ( FBLMAIN_BM_TYPES_VERSION != 0x0200u ) || \
    ( FBLMAIN_BM_TYPES_RELEASE_VERSION != 0x00u )
# error "Error in fbl_bm.c: Source and header file are inconsistent!"
#endif

#define FBL_BM_START_SEC_CODE
#include "MemMap.h"
/***********************************************************************************************************************
 *   PROTOTYPES
 **********************************************************************************************************************/
static void FblBmCheckBootConditions(void);

/***********************************************************************************************************************
 *   FUNCTIONS
 **********************************************************************************************************************/

/***********************************************************************************************************************
 *  main
 **********************************************************************************************************************/
/*! \brief       Bootmanager main function
 *  \details     Calls basic initialization function and performs boot checks.
 **********************************************************************************************************************/
int V_API_NEAR main(void)
{
   ApplBmInit();

   FblBmCheckBootConditions();

   /* No valid boot application found */
   ApplBmFatalError(0u);

   return 0;
}

/***********************************************************************************************************************
 *  FblBmCheckBootConditions
 **********************************************************************************************************************/
/*! \brief       Check of boot conditions
 *  \details     Function processes the list of check entries. 
 **********************************************************************************************************************/
static void V_API_NEAR FblBmCheckBootConditions(void)
{
   vuint8 checkIndex;

   checkIndex = 0u;
   while( (checkIndex < kBmNrOfCheckEntries) )
   {
      /* Call configured check function */
      if (  (*(bmCheckList[checkIndex].bmCheckBootCondFct))( bmCheckList[checkIndex].bmTargetHandle ) == kFblOk)
      {
         (*(bmCheckList[checkIndex].bmCallFct))( bmCheckList[checkIndex].bmTargetHandle );
      }

      checkIndex++;
   }
}
#define FBL_BM_STOP_SEC_CODE
#include "MemMap.h"

/***********************************************************************************************************************
 *  END OF FILE: FBL_BM.C
 **********************************************************************************************************************/

